package com.mive.service;

import com.mive.entity.Author;
import com.mive.repository.AuthorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("authorJpaService")
public class AuthorJpaService {

    @Autowired
    private AuthorRepository authorRepository;

    public void create(Author author){
        this.authorRepository.save(author);
    }

    public List<Author> findAll(){
        return this.authorRepository.findAll();
    }

    public Page<Author> findAll(Pageable pageable){
        return this.authorRepository.findAll(pageable);
    }

    public Author findByName(String realName){
        return this.authorRepository.findAuthorByRealName(realName);
    }

    public Author findAuthor(Long id){
        return this.authorRepository.findAuthor(id);
    }
}
